import { CUSTOMER_INFO, CLEAR_INFO, CUSTOMER_LIST } from "../constants/customer";

const INITIAL_STATE = {
  cnt: "-",
  cnt1: "-",
  cnt3: "-",
  cnt4: "-",
  cnt0: "-",
  daycnt: "-",
  tcnt: "-",
  report: {},
  list: [],
  page:1
};

export default function customer(state = INITIAL_STATE, action) {
  switch (action.type) {
    case CUSTOMER_INFO:
      return {
        ...state,
        ...action
      };
    case CUSTOMER_LIST:
      return {
        ...state,
        list: action.page === 1 ? [...action.list] : [...state.list,...action.list],
        page: action.page
      }
    case CLEAR_INFO:
      return {
        cnt: "-",
        cnt1: "-",
        cnt3: "-",
        cnt4: "-",
        cnt0: "-",
        daycnt: "-",
        tcnt: "-",
        report: {}
      };
    default:
      return { ...state };
  }
}
